<?php
namespace app\api\validate\haipi;

use think\Validate;

class Post extends Validate
{
    protected $rule = [
        'title'   => 'require|length:4,20',
        'age'     => 'require',
        'height'  => ['require', 'regex:/^(\d{1,3})(cm|厘米|公分|米)?$/i'],
        'weight'  => ['require', 'regex:/^(\d{1,3})(kg|千克|公斤|斤)?$/i'],
        'bust'    => 'require|length:2,4',
        'price'   => 'require|length:2,20',
        'service' => 'require|length:10,200',
        'address' => 'require|length:4,200',
        'mobile'  => 'mobile',
        'wx'      => 'length:4,20',
        'qq'      => 'length:4,20',
        'images'  => 'require|array|min:2'
    ];

    protected $message = [
        'title.require'   => '请输入标题',
        'title.length'    => '标题长度在4~20之间',
        'age.require'     => '请输入年龄',
        'height.require'  => '请输入身高',
        'height.regex'    => '身高格式不正确，请输入如:180、180cm、180厘米、180公分',
        'weight.require'  => '请输入体重',
        'weight.regex'    => '体重格式不正确，请输入如:55、55kg、55公斤、110斤',
        'bust.require'    => '请输入胸围',
        'bust.length'     => '胸围格式不正确',
        'price.require'   => '请输入价格',
        'price.length'    => '价格格式不正确',
        'service.require' => '请输入服务',
        'service.length'  => '服务长度在10~200之间',
        'address.require' => '请输入详细地址',
        'address.length'  => '地址长度在4~200之间',
        'mobile.mobile'   => '手机格式不正确',
        'wx.length'       => '微信格式不正确',
        'qq.length'       => 'QQ格式不正确',
        'images.require'  => '请上传图集',
        'images.min'      => '请至少上传两张图片'
    ];

    protected function checkContact($value, $rule, $data)
    {
        if (empty($data['mobile']) && empty($data['wx']) && empty($data['qq'])) {
            return '手机，微信，QQ可任填其一';
        }
        return true;
    }
}